
package BLL.AdminSys;


import BIZ.UserBiz;
import javabean.userDetails;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet(name = "AdminChangeCharge", value = "/AdminChangeCharge")
public class AdminChangeCharge extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public AdminChangeCharge() {
        super();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();



        String Balance;
        String remainingDays;
        String remainDegree;
        String Type;

        //从表单获取数据
        String UserName = new String(request.getParameter("UserName").getBytes(StandardCharsets.UTF_8));
        String Password = new String(request.getParameter("Password").getBytes(StandardCharsets.UTF_8));

        UserBiz userBiz = new UserBiz();
        userDetails user = userBiz.getuser(UserName, Password);


        //判断用户是否存在
        if (user != null) {

            //判断用户类型
            Type = userBiz.getusertype(UserName);
            if (Type.equals("0")) {
                //由Mysql调用数据
                Balance = userBiz.getuserbalance(UserName);
                remainingDays = userBiz.getRemainDay(UserName);
                boolean x=userBiz.changeremaindayordegree(remainingDays,Type,UserName,Balance);



            }
            if (Type.equals("1")) {
                //由Mysql调用数据

                Balance = userBiz.getuserbalance(UserName);
                remainDegree = userBiz.getRemainDegree(UserName);
                boolean x=userBiz.changeremaindayordegree(remainDegree,Type,UserName,Balance);
            }
        }

        //未找到账户信息
        if ( user == null) {
            System.out.println("0");

            session.setAttribute("error3", 0);
        }



    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
